package cn.gailvlun.gll.widget.photopicker;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import com.github.markzhai.recyclerview.BindingViewHolder;

import cn.gailvlun.gll.databinding.ItemPhotoPhotoBinding;



public class PhotoPickerItemHelper extends ItemTouchHelper.Callback {

    private PhotoPickerItemAdapter mAdapter;

    public PhotoPickerItemHelper(PhotoPickerItemAdapter mAdapter) {
        this.mAdapter = mAdapter;
    }

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        
        int dragFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
        return makeMovementFlags(dragFlags, 0);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        if (viewHolder instanceof BindingViewHolder && target instanceof BindingViewHolder
                && ((BindingViewHolder) viewHolder).getBinding() instanceof ItemPhotoPhotoBinding
                && ((BindingViewHolder) target).getBinding() instanceof ItemPhotoPhotoBinding) {
            mAdapter.onDrag(viewHolder.getAdapterPosition(), target.getAdapterPosition());
            return true;
        }
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {

    }
}
